package com.hxy.health.platform.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxy.health.platform.dao.CommentMapper;
import com.hxy.health.platform.pojo.Comment;
import com.hxy.health.platform.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;
    /**
     * 添加新评论
     * @param comment
     * @return
     */
    @Override
    public int addComment(Comment comment) {
        Comment newComment = new Comment();
        newComment.setArticleId(comment.getArticleId());
        newComment.setContent(comment.getContent());
        newComment.setEmail(comment.getEmail());
        newComment.setUsername(comment.getUsername());
        return commentMapper.insertSelective(newComment);
    }

    /**
     * 查看本文章所有评论
     * @param id
     * @return
     */
    @Override
    public PageInfo<Comment> getByArticleId(Integer pageNum, Integer pageSize,Integer id) {
        PageHelper.startPage(pageNum, pageSize);
        List<Comment> commentList = commentMapper.getByArticleId(id);
        PageInfo<Comment> pageHelper = new PageInfo<>(commentList);
        return pageHelper;
    }
}
